Skip to content

lib: read class and type names for logs without nameof's fixed offsets - #24

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/reflection-class-name
Oct 11, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/reflection-class-name

Conversation

@EnzinoBB

Copy link
Copy Markdown
Collaborator

Problem

The csmeta / csname log helpers (className()) and csexpression / cstype take type names from nameof. nameof cuts the name out of __PRETTY_FUNCTION__ at fixed offsets (GCC: +98, -151) that match the signature format of older GCC versions. With GCC 13 the computed length is negative, i.e. close to SIZE_MAX:

Node: size=18446744073709551604

Every log line that prints a class or type name therefore reads far past the string, and the node dies with a segmentation fault. 58 warning and error lines use these helpers. Most are on error paths; three are on network input (Compressor decompression errors), so on such a build a malformed packet from a peer could take the node down.

Official release binaries are built with an older GCC and are probably unaffected. Any build with a current toolchain is affected.

Found on the test network. A pruned node (#22) crashed when a joining node asked it for blocks it had pruned. The core dump backtrace:

#1 boost::log::...::basic_formatting_ostream<char>::aligned_write(char const*, long)
#2 boost::log::...::basic_formatting_ostream<char>::formatted_write(char const*, long)
#3 Node::getBlockRequest(unsigned char const*, unsigned long, std::array<unsigned char, 32ul> const&)
#4 Transport::processorRoutine()

The line is csmeta(cslog) << "unable to load block " ..., which runs only when a requested block is missing.

Fix

cs::reflection::typeName<T>() in lib/include/lib/system/reflection.hpp reads the name from the compiler's signature by its T = marker, for GCC ([with T = X; ...]) and clang ([T = X]). Other compilers keep nameof. className(), csexpression and cstype use it. No other file changes.

Verification

  • New lib test Reflection.TypeNamesAreExact. It checks a polymorphic class, a plain struct, cstype(int) and csexpression. system tests pass 50/50, nodetests 134/134.
  • Test network: see csnode, csdb: pruned storage #22, where the pruned node serving requests for pruned blocks is exercised with this fix.

🤖 Generated with Claude Code

The csmeta/csname log helpers (className()) and csexpression/cstype took type names from
nameof, which cuts them out of __PRETTY_FUNCTION__ at fixed offsets matching older GCC versions.
With GCC 13 the computed length is negative, that is huge, so each log line printing a class or
type name read far past the string and the node died with a segmentation fault. 58 warning and
error lines use them, three of them on network input (Compressor decompression errors).

Found on the test network: a pruned node crashed in Node::getBlockRequest, logging "unable to
load block" with csmeta(cslog) as a joining node asked for blocks it had pruned (core dump
backtrace: getBlockRequest -> boost::log formatted_write).

cs::reflection::typeName<T>() reads the name from the compiler's signature by its "T = "
marker instead, for GCC and clang; other compilers keep nameof. Lib test
Reflection.TypeNamesAreExact pins the names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit e8ddeef into master Oct 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant